package com.lee.controller;

import com.lee.bean.Staff;
import com.lee.service.StaffService;
import com.lee.util.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by dllo on 18/4/16.
 */
@Controller
public class LoginController {
    @Resource
    private StaffService staffService;

    @RequestMapping(value = "/login")
    public String login(){
        return "/login";
    }

    @RequestMapping(value = "frame")
    public String frame(){
        return "frame";
    }
    @RequestMapping(value = "top")
    public String top(){
        return "frame/top";
    }
    @RequestMapping(value = "left1")
    public String left1(){
        return "frame/left1";
    }
    @RequestMapping(value = "left")
    public String left(){
        return "frame/left";
    }
    @RequestMapping(value = "left2")
    public String left2(){
        return "frame/left2";
    }
    @RequestMapping(value = "control")
    public String control(){
        return "frame/control";
    }
    @RequestMapping(value = "right")
    public String right(){
        return "frame/right";
    }

    @ResponseBody
    @RequestMapping(value = "dologin")
    public AjaxResult doLogin(HttpServletRequest request,@RequestParam("username")String username, @RequestParam("password")String password){
        AjaxResult result = new AjaxResult();
        if (username == null || password == null ||username.isEmpty()||password.isEmpty()){
            result.setCode("0");
            result.setMessage("请填写用户名和密码");
            return result;
        }
        Staff staff = new Staff();
        staff.setLoginname(username);
        staff.setLoginpwd(password);
        result = staffService.doLogin(staff);
        Staff newStaff = (Staff) result.getData();
        request.getSession().setAttribute("name",newStaff.getStaffname());
        request.getSession().setAttribute("sid",newStaff.getStaffid());
        return result;
    }
}
